package com.lipaluma.example.clients.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="t_order")
@NamedQueries({
	@NamedQuery(name="Orders.findLastCreatedForAccount", query="select object(o) from Order o where o.status = 'CREATED' and o.account = :account"),
})
public class Order {

	@Id
	@GeneratedValue
	private Long id;
	
	@ManyToOne
	private Account account;
	
	@OneToMany(mappedBy="order", cascade={CascadeType.ALL})
	//@JoinColumn(name="order_id")
	private List<LineOrder> lines;
	
	private double totalAmount;
	
	@Enumerated(EnumType.STRING)
	private StatusEnum status;

	public enum StatusEnum {
		CREATED, INVOICED, PAID
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public List<LineOrder> getLines() {
		return lines;
	}
	public void setLines(List<LineOrder> lines) {
		this.lines = lines;
	}
	public double getTotalAmount() {
		return totalAmount;
	}
	public void setTotalAmount(double totalAmount) {
		this.totalAmount = totalAmount;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
	public StatusEnum getStatus() {
		return status;
	}
	public void setStatus(StatusEnum status) {
		this.status = status;
	}
}
